﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media;
using DevExpress.Xpf.Scheduler;

namespace Agnes.TaskManager
{
    class StringToLabelConvter : IValueConverter
    {
        /// <summary>
        /// Convert
        /// </summary>
        /// <param name="value">String</param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns>AppointmentLabel</returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            foreach (AppointmentLabel i in TaskManagerService.TaskManager.SchedulerStorage.AppointmentStorage.Labels)
            {
                if (i.DisplayName == (string)value)
                {
                    return i;
                }
                
            }

            return null;
        }

        /// <summary>
        /// ConvertBack
        /// </summary>
        /// <param name="value">AppointmentLabel</param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns>string</returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return "";
            }

            return (value as AppointmentLabel).DisplayName;
        }
    }
}
